package it.polimi.TravelDream.ejb.entities;

import it.polimi.TravelDream.ejb.dtos.PackageDTO;

import java.io.Serializable;
import java.lang.String;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.*;

import org.hibernate.validator.constraints.NotEmpty;

/**
 * Entity implementation class for Entity: BasicPackage
 *
 */
@Entity
@Table(name = "packages")
@NamedQueries({
	@NamedQuery(name = BasicPackage.FIND_PACKAGES_BY_NAME , query = "SELECT p FROM BasicPackage p WHERE p.name = :name"),
	@NamedQuery(name = "findPackagesByPartialName", query = "SELECT p FROM BasicPackage p WHERE p.name LIKE :name"),
	@NamedQuery(name = BasicPackage.FIND_ALL_PACKAGE, query = "SELECT p FROM BasicPackage p"),
	@NamedQuery(name = BasicPackage.FIND_ALL_AVAILABLE_PACKAGE, query = "SELECT p FROM BasicPackage p WHERE p.placesAvailable>0"),
	@NamedQuery(name = BasicPackage.FIND_PACKAGES_BY_CITY, query = "SELECT p FROM BasicPackage p WHERE p.city = :city"),
	@NamedQuery(name = BasicPackage.FIND_PACKAGES_BY_NATION, query = "SELECT p FROM BasicPackage p WHERE p.nation = :nation"),
	@NamedQuery(name = BasicPackage.FIND_PACKAGES_LAST_MINUTE, query = "Select p FROM BasicPackage p WHERE p.lastMinute = TRUE"),
	@NamedQuery(name = BasicPackage.FIND_PACKAGES_BY_TRAVELID, query = "SELECT p FROM BasicPackage p WHERE p.travelID= :travelID"),
	@NamedQuery(name = BasicPackage.FIND_PACKAGES_BY_EXPIRATION_DATE, query = "SELECT p FROM BasicPackage p WHERE p.expirationDate= :expirationDate"),
	@NamedQuery(name = BasicPackage.FIND_PACKAGES_BY_EXPIRATION_DATE_AND_NAME, query = "SELECT p FROM BasicPackage p WHERE p.expirationDate= :expirationDate and p.name= :name"),
	@NamedQuery(name = BasicPackage.FIND_PACKAGES_BY_EXPIRATION_DATE_AND_CITY, query = "SELECT p FROM BasicPackage p WHERE p.expirationDate= :expirationDate and p.city= :city"),
	@NamedQuery(name = BasicPackage.FIND_PACKAGES_BY_NAME_AND_CITY , query = "SELECT p FROM BasicPackage p WHERE p.name = :name and p.city= :city"),
	@NamedQuery(name = BasicPackage.FIND_PACKAGES_BY_NAME_CITY_AND_EXPIRATION_DATE , query = "SELECT p FROM BasicPackage p WHERE p.name = :name and p.city= :city and p.expirationDate= :expirationDate"),
})
public class BasicPackage implements Serializable {

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int travelID;
	@Column(length = 30)
	@NotEmpty
	private String name;
	@Column(length = 200)
	@NotEmpty
	private String description;
	@Column(length = 30)
	@NotEmpty
	private String city;
	@Column(length = 30)
	@NotEmpty
	private String nation;
	@Temporal(TemporalType.DATE)
	private Date startingDate;
	@Temporal(TemporalType.DATE)
	private Date expirationDate;
	private int placesAvailable;
	private boolean lastMinute;
	
	//Impiegato che ha creato il pacchetto
	@ManyToOne(optional = false)
	@JoinColumn(name = "users_username", referencedColumnName = "username")
	private User employee;

	//Escursioni contenute nel pacchetto
	@ManyToMany
	@JoinTable(name = "package_excursion",
		joinColumns = @JoinColumn(name = "packages_travelID"),
		inverseJoinColumns = @JoinColumn(name = "excursions_excursionID"))
	private List <Excursion> excursions;

	//Camere contenute nel pacchetto
	@ManyToMany
	@JoinTable(name = "package_room",
		joinColumns = @JoinColumn(name = "packages_travelID"),
		inverseJoinColumns = @JoinColumn(name = "rooms_roomID"))
	private List <Room> rooms;

	//Camere contenute nel pacchetto
	@ManyToMany
	@JoinTable(name = "package_flight",
		joinColumns = @JoinColumn(name = "packages_travelID"),
		inverseJoinColumns = @JoinColumn(name = "flights_flightID"))
	private List <Flight> flights;
	
	public static final long serialVersionUID = 1L;
	public static final String FIND_PACKAGES_BY_NAME = "BasicPackage.findPackagesByName";
	public static final String FIND_ALL_PACKAGE = "BasicPackage.findAllPackage";
	public static final String FIND_ALL_AVAILABLE_PACKAGE = "BasicPackage.findAllAvailablePackage";
	public static final String FIND_PACKAGES_BY_CITY = "BasicPackage.findPackagesByCity";
	public static final String FIND_PACKAGES_BY_NATION = "BasicPackage.findPackagesByNation";
	public static final String FIND_PACKAGES_LAST_MINUTE = "BasicPackage.findPackagesLastMinute";
	public static final String FIND_PACKAGES_BY_TRAVELID = "BasicPackage.findPackagesByTravelID";
	public static final String FIND_PACKAGES_BY_EXPIRATION_DATE = "BasicPackage.findPackagesByExpirationDate";
	public static final String FIND_PACKAGES_BY_EXPIRATION_DATE_AND_NAME = "BasicPackage.findPackagesByExpirationDateAndName";
	public static final String FIND_PACKAGES_BY_EXPIRATION_DATE_AND_CITY = "BasicPackage.findPackagesByExpirationDateAndCity";
	public static final String FIND_PACKAGES_BY_NAME_AND_CITY = "BasicPackage.findPackagesByNameAndCity";
	public static final String FIND_PACKAGES_BY_NAME_CITY_AND_EXPIRATION_DATE = "BasicPackage.findPackagesByNameAndCityAndExpirationDate";
	
	public BasicPackage() {
		flights = new ArrayList<Flight>();
		excursions = new ArrayList<Excursion>();
		rooms = new ArrayList<Room>();
	}   
	
	public BasicPackage(PackageDTO packageDTO) {
		super();
		this.name = packageDTO.getName();
		this.description = packageDTO.getDescription();
		this.city = packageDTO.getCity();
		this.nation = packageDTO.getNation();
		this.startingDate = packageDTO.getStartingDate();
		this.expirationDate = packageDTO.getExpirationDate();
		this.placesAvailable = packageDTO.getPlacesAvailable();
		this.lastMinute = packageDTO.isLastMinute();

		flights = new ArrayList<Flight>();
		excursions = new ArrayList<Excursion>();
		rooms = new ArrayList<Room>();

	}
	
	public int getTravelID() {
		return this.travelID;
	}

	public void setTravelID(int travelID) {
		this.travelID = travelID;
	}   
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}   
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}   
	public String getCity() {
		return this.city;
	}

	public void setCity(String city) {
		this.city = city;
	}   
	public String getNation() {
		return this.nation;
	}

	public void setNation(String nation) {
		this.nation = nation;
	}   
	public Date getStartingDate() {
		return this.startingDate;
	}

	public void setStartingDate(Date startingDate) {
		this.startingDate = startingDate;
	}   
	public Date getExpirationDate() {
		return this.expirationDate;
	}

	public void setExpirationDate(Date expirationDate) {
		this.expirationDate = expirationDate;
	}   
	public int getPlacesAvailable() {
		return this.placesAvailable;
	}

	public void setPlacesAvailable(int placesAvailable) {
		this.placesAvailable = placesAvailable;
	}   

	public boolean getLastMinute() {
		return this.lastMinute;
	}

	public void setLastMinute(boolean lastMinute) {
		this.lastMinute = lastMinute;
	}   

	public User getEmployee() {
		return employee;
	}
	public void setEmployee(User employee) {
		this.employee = employee;
	}

	public List<Excursion> getExcursions() {
		return excursions;
	}

	public void setExcursions(List<Excursion> excursions) {
		this.excursions = excursions;
	}

	public List<Room> getRooms() {
		return rooms;
	}

	public void setRooms(List<Room> rooms) {
		this.rooms = rooms;
	}

	public List<Flight> getFlights() {
		return flights;
	}

	public void setFlights(List<Flight> flights) {
		this.flights = flights;
	}

}
